package com.wanxi.education.model.vo.user;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

/**
 * @Author: zhe
 * @Date: 2021/9/24 16:19
 * @Description: 权限
 * @Version: 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("权限Model")
public class UserVO implements UserDetails {

    @ApiModelProperty(value = "ID",dataType = "Long")
    private Long id;

    @ApiModelProperty(value = "昵称",dataType = "String")
    private String username;

    @ApiModelProperty(value = "电话号码",dataType = "String")
    private String phone;

    @ApiModelProperty(value = "密码",dataType = "String")
    private String password;

    @ApiModelProperty(value = "权限",dataType = "list")
    private Set<GrantedAuthority> authorizations;

    @ApiModelProperty(value = "用户状态：0:管理员 1：机构负责人 2：学员(可忽略)",hidden = true)
    private Integer state;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return getAuthorizations();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public UserVO(Long id, String username, String phone, String password, Set<GrantedAuthority> authorizations) {
        this.id = id;
        this.username = username;
        this.phone = phone;
        this.password = password;
        this.authorizations = authorizations;
    }
}
